<template>
    <div>
<h2>修改积分</h2>
<table class="table table-bordered">
<tr>
    <td>积分</td>
    <td><input type="text" v-model="jifen" /></td>
</tr>
<tr>
    <td></td>
    <td>
        <input type="button" value="增加" @click="change(num)" />
        <input type="button" value="减少" @click="change(-num)" />
    </td>
</tr>
<tr>
    <td></td>
    <td><input type="button" value="保存" @click="upd" /></td>
</tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let data:any = reactive({
   
        jifen: "",
        num: 10,

 
})
let { jifen,num } = toRefs(data)
onMounted(()=>{
    getlist()
})
const getlist=()=>{
    let obj = {
       id:route.query.id
    }
    axios({
        url: '/api/Member/GetMember',
        method: 'get',
        params: obj
    })
        .then(res => {
            console.log(res)
           jifen.value=res.data.data.jifen

        })
        .catch(err => {
            console.log(err)
        })
}
const change=(num:any)=>{
if(num<0&&Number(jifen.value)<=0){
    return
}
jifen.value=jifen.value+num
}
const upd=()=>{
    let obj = {
       id:route.query.id,
       jifen: jifen.value
    }
    axios({
        url: '/api/Member/updatejifen',
        method: 'post',
        params: obj
    })
        .then(res => {
            console.log(res)
           if(res.data.data==1){
            alert("修改成功")
            router.push("/list")
           }
           else{
            alert("修改失败")
           }

        })
        .catch(err => {
            console.log(err)
        })
}
</script>

<style scoped>

</style>